'use strict';

/**
 * @description: 将params code 转成 object
 * @param {string} [queryString]
 * @return {*} object
 */
const decodeParams = (queryString) => {
    const params = new URLSearchParams(queryString);
    // 使用 Array.from 将迭代器转换为数组，然后使用 reduce 将数组转换为对象
    return Array.from(params.entries()).reduce((acc, [key, value]) => {
        acc[key] = value;
        return acc;
    }, {});
};
/**
 * @description: 将params code 转成 object
 * @param {objct} [str:string]:any
 * @return {*} string
 */
const encodeParams = (query) => {
    const queryString = "?" + new URLSearchParams(query).toString();
    return queryString;
};
// - "?name=zhangsan&age=12&sex=1"
// { name: "zhangsan", age: "12", sex: "1" };

exports.decodeParams = decodeParams;
exports.encodeParams = encodeParams;
